package com.boarsoft.boar.soagov.file.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.app.AppBiz;
import com.boarsoft.boar.entity.ServerInfo;
import com.boarsoft.boar.file.action.FileAction;
import com.boarsoft.boar.soagov.entity.FileSoagovInfo;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.Util;
import com.boarsoft.common.util.JsonUtil;

@RestController
@RequestMapping("/file")
public class FileSoagovAction extends FileAction {

	@Autowired
	protected AppBiz appBiz;

	/**
	 * 在树上某个应用下增加配置文件需操作两张表 1，向file_info插入配置文件基础数据 2，向app_file插入应用与配置文件的关联关系记录
	 * @return 
	 */
	@RequestMapping("/save.do")
	@Authorized(code = "file.save")
	public ReplyInfo<String> save(String appId, FileSoagovInfo a) {
		a.setStatus(ServerInfo.STATUS_RUNNING);
		a.setCreateTime(Util.getStdfDateTime());
		a.setLastTime(Util.getStdfDateTime());
		fileBiz.save(appId, a);
		return new ReplyInfo<String>(true, JsonUtil.from(a, "apps"));
	}

	/**
	 * 在树上某个应用下增加配置文件需操作两张表 1，向file_info插入配置文件基础数据 2，向app_file插入应用与配置文件的关联关系记录
	 * @return 
	 */
	@RequestMapping("/update.do")
	@Authorized(code = "file.update")
	public ReplyInfo<String> update(String appId, FileSoagovInfo o) {
		FileSoagovInfo a = (FileSoagovInfo) fileBiz.get(o.getId());
		a.setCode(o.getCode());
		a.setName(o.getName());
		a.setDeployPath(o.getDeployPath());
		a.setLastTime(Util.getStdfDateTime());
		a.setType(o.getType());
		a.setMemo(o.getMemo());
		fileBiz.update(appId, a);
		return new ReplyInfo<String>(true, JsonUtil.from(a, "apps"));
	}
}